package cn.csg.iotplatform.module.system.api.dept;

import cn.csg.iotplatform.framework.common.pojo.CommonResult;
import cn.csg.iotplatform.framework.common.util.collection.CollectionUtils;
import cn.csg.iotplatform.module.system.api.dept.dto.AdministrationDTO;
import cn.csg.iotplatform.module.system.api.dept.dto.DeptRespDTO;
import cn.csg.iotplatform.module.system.api.dept.dto.GetDeptDtoObjAllListRespDTO;
import cn.csg.iotplatform.module.system.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

@FeignClient(name = ApiConstants.NAME) // TODO 芋艿：fallbackFactory =
@Tag(name = "RPC 服务 - 部门")
public interface DeptApi {

    String PREFIX = ApiConstants.PREFIX + "/dept";

    @GetMapping(PREFIX + "/get")
    @Operation(summary = "获得部门信息")
    @Parameter(name = "id", description = "部门编号", example = "1024", required = true)
    CommonResult<DeptRespDTO> getDept(@RequestParam("id") Long id);

    @GetMapping(PREFIX + "/getAsynVersion")
    @Operation(summary = "获得部门信息")
    @Parameter(name = "id", description = "部门编号", example = "1024", required = true)
    CommonResult<DeptRespDTO> getDeptAsynVersion(@RequestParam("id") Long id, @RequestHeader("Authorization") String authorization);


    @GetMapping(PREFIX + "/getDeptByUserIdsToDeptMap")
    @Operation(summary = "获得部门信息根据用户Id")
    @Parameter(name = "userIds", description = "部门编号", example = "1024", required = true)
    CommonResult<Map<Long, DeptRespDTO>> getDeptByUserIdsToDeptMap(@RequestParam("userId") Collection<Long> userId);

    @GetMapping(PREFIX + "/getDeptByOrgId")
    @Operation(summary = "获得部门信息")
    @Parameter(name = "orgId", description = "单位id", example = "10000", required = true)
    CommonResult<DeptRespDTO> getDeptByOrgId(@RequestParam("orgId") String orgId);

    @GetMapping(PREFIX + "/getDeptBySapHrOrgId")
    @Operation(summary = "获得部门信息")
    @Parameters({@Parameter(name = "sapHrOrgId", description = "单位id", example = "10000", required = true),
        @Parameter(name = "eqOrgCode", description = "局编码", example = "10000", required = true)})
    CommonResult<DeptRespDTO> getDeptBySapHrOrgId(@RequestParam("sapHrOrgId") String sapHrOrgId,@RequestParam("eqOrgCode") String eqOrgCode);

    @GetMapping(PREFIX + "/list")
    @Operation(summary = "获得部门信息数组")
    @Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)
    CommonResult<List<DeptRespDTO>> getDeptList(@RequestParam("ids") Collection<Long> ids);

    @GetMapping(PREFIX + "/pageList")
    @Operation(summary = "获得部门信息list")
    CommonResult<List<Map<String, Object>>> getDeptAllList();

    @GetMapping(PREFIX + "/pageDtoList")
    @Operation(summary = "获得部门信息list（DTO对象返回值）")
    CommonResult<List<GetDeptDtoObjAllListRespDTO>> getDeptDtoObjAllList();

    @GetMapping(PREFIX + "/valid")
    @Operation(summary = "校验部门是否合法")
    @Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)
    CommonResult<Boolean> validateDeptList(@RequestParam("ids") Collection<Long> ids);

    @GetMapping(PREFIX + "/getChildDeptIds")
    @Operation(summary = "获取包含下级部门的id集合")
    @Parameter(name = "parentId", description = "部门id", example = "1", required = true)
    CommonResult<Set<Long>> getChildDeptIds(@RequestParam("id") Long parentId);

    @GetMapping(PREFIX + "/getDeptAreaSetting")
    @Operation(summary = "查询行政区域设置")
    @Parameter(name = "unitId", description = "部门id", example = "1", required = true)
    CommonResult<List<AdministrationDTO>> getDeptAreaSetting(@RequestParam("unitId") Long unitId);


    @GetMapping(PREFIX + "/queryDeptList")
    @Operation(summary = "获得部门信息数组")
    CommonResult<List<DeptRespDTO>> queryDeptList();
}
